#ifndef __STM32F4xx_AES_H
#define __STM32F4xx_AES_H

#ifdef __cplusplus
 extern "C" {
#endif

#include "stm32f4xx.h"

/* AES寄存器位定义 */
#define AES_CR_EN              ((uint32_t)0x00000001)
#define AES_CR_DATATYPE        ((uint32_t)0x00000006)
#define AES_CR_MODE            ((uint32_t)0x00000018)
#define AES_CR_CHMOD           ((uint32_t)0x00000060)
#define AES_CR_CCFC            ((uint32_t)0x00000080)
#define AES_CR_ERRC            ((uint32_t)0x00000100)
#define AES_CR_CCFIE           ((uint32_t)0x00000200)
#define AES_CR_ERRIE           ((uint32_t)0x00000400)
#define AES_CR_DMAINEN         ((uint32_t)0x00000800)
#define AES_CR_DMAOUTEN        ((uint32_t)0x00001000)
#define AES_CR_GCMPH          ((uint32_t)0x00006000)

/* AESData长度定义 */
#define AES_DATATYPE_32B       ((uint32_t)0x00000000)
#define AES_DATATYPE_16B       ((uint32_t)0x00000002)
#define AES_DATATYPE_8B        ((uint32_t)0x00000004)
#define AES_DATATYPE_1B        ((uint32_t)0x00000006)

/* AES模式定义 */
#define AES_MODE_ENCRYPTION    ((uint32_t)0x00000000)
#define AES_MODE_KEYDERIVATION ((uint32_t)0x00000008)
#define AES_MODE_DECRYPTION    ((uint32_t)0x00000010)
#define AES_MODE_KEYDERIVATION_DECRYPTION ((uint32_t)0x00000018)

/* AES链模式定义 */
#define AES_CHAINMODE_ECB      ((uint32_t)0x00000000)
#define AES_CHAINMODE_CBC      ((uint32_t)0x00000020)
#define AES_CHAINMODE_GCM      ((uint32_t)0x00000040)

/* AESStatus寄存器位定义 */
#define AES_SR_CCF             ((uint32_t)0x00000001)
#define AES_SR_RDERR           ((uint32_t)0x00000002)
#define AES_SR_WRERR           ((uint32_t)0x00000004)

/* AESKey长度 */
#define AES_KEY_SIZE           16  // 128位Key
#define AES_BLOCK_SIZE         16  // 128位块大小

/* AESCommand定义 */
#define AES_CMD_SET_PASSWORD   0x01
#define AES_CMD_ENCRYPT        0x02
#define AES_CMD_DECRYPT        0x03

/* Function声明 */
void AES_DeInit(void);
void AES_Init(void);
void AES_Enable(void);
void AES_Disable(void);
void AES_SetKey(uint8_t* key);
void AES_SetIV(uint8_t* iv);
void AES_Encrypt(uint8_t* plaintext, uint8_t* ciphertext, uint32_t length);
void AES_Decrypt(uint8_t* ciphertext, uint8_t* plaintext, uint32_t length);
void AES_ProcessCommand(uint8_t cmd, uint8_t* data, uint32_t length, uint8_t* response, uint32_t* response_length);
void AES_SetPassword(uint8_t* password, uint32_t length);

#ifdef __cplusplus
}
#endif

#endif /* __STM32F4xx_AES_H */
